package view;

import controller.UnidadeCtrl;
import java.awt.BorderLayout;
import javax.swing.*;
import model.Observer;

public class UnidadeUI extends javax.swing.JFrame implements Observer{
    
    UnidadeCtrl unidadeCtrl;
                
    public UnidadeUI(UnidadeCtrl unidadeCtrl) {
        this.unidadeCtrl = unidadeCtrl;        
    }
     
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel4 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        txtCodigo = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        txtDescricao = new javax.swing.JTextField();
        panelTable = new javax.swing.JPanel();
        comboPesquisa = new javax.swing.JComboBox();
        txtPesquisa = new javax.swing.JTextField();
        btnPesquisar = new javax.swing.JButton();
        jSeparator12 = new javax.swing.JSeparator();
        jSeparator13 = new javax.swing.JSeparator();
        jLabel10 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        btnPrimeiro = new javax.swing.JButton();
        btnAnterior = new javax.swing.JButton();
        btnProximo = new javax.swing.JButton();
        btnUltimo = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblUnidades = new javax.swing.JTable();
        lblRowCount = new javax.swing.JLabel();
        jToolBar1 = new javax.swing.JToolBar();
        btnNovo = new javax.swing.JButton();
        btnAlterar = new javax.swing.JButton();
        btnSalvar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnExcluir = new javax.swing.JButton();
        btnPesquisar1 = new javax.swing.JButton();
        panelStatusBar = new javax.swing.JPanel();
        lblStatusBar = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Controle de Unidades");
        setBackground(new java.awt.Color(236, 255, 249));
        setMinimumSize(new java.awt.Dimension(679, 396));
        setResizable(false);

        jPanel4.setBackground(new java.awt.Color(229, 223, 223));
        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED, java.awt.Color.gray, null));

        jPanel1.setBackground(new java.awt.Color(217, 228, 231));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(102, 0, 255), new java.awt.Color(102, 0, 255)), "Dados da Unidade", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(0, 0, 0))); // NOI18N
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel12.setText("Código:");
        jPanel1.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 30, -1, -1));

        txtCodigo.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        txtCodigo.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtCodigo.setEnabled(false);
        jPanel1.add(txtCodigo, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 50, 220, 20));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setText("Descrição:");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 30, -1, -1));

        txtDescricao.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        txtDescricao.setToolTipText("");
        jPanel1.add(txtDescricao, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 50, 400, -1));

        panelTable.setBackground(new java.awt.Color(217, 228, 231));
        panelTable.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED, new java.awt.Color(102, 0, 255), new java.awt.Color(102, 0, 255)), "Unidades", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12), java.awt.Color.black)); // NOI18N
        panelTable.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        comboPesquisa.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        comboPesquisa.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        panelTable.add(comboPesquisa, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 40, 90, 20));

        txtPesquisa.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        panelTable.add(txtPesquisa, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 40, 420, 20));

        btnPesquisar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnPesquisar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/pesquisar.png"))); // NOI18N
        btnPesquisar.setMnemonic('C');
        btnPesquisar.setText("Buscar");
        btnPesquisar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        panelTable.add(btnPesquisar, new org.netbeans.lib.awtextra.AbsoluteConstraints(570, 30, 100, 30));

        jSeparator12.setOrientation(javax.swing.SwingConstants.VERTICAL);
        panelTable.add(jSeparator12, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 40, 10, 20));

        jSeparator13.setOrientation(javax.swing.SwingConstants.VERTICAL);
        panelTable.add(jSeparator13, new org.netbeans.lib.awtextra.AbsoluteConstraints(560, 30, 10, 30));

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel10.setText("Pesquisar Por:");
        panelTable.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, 130, -1));

        jPanel6.setBackground(new java.awt.Color(217, 228, 231));
        jPanel6.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btnPrimeiro.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnPrimeiro.setText("<<");
        btnPrimeiro.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jPanel6.add(btnPrimeiro);

        btnAnterior.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnAnterior.setText("<");
        btnAnterior.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jPanel6.add(btnAnterior);

        btnProximo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnProximo.setText(">");
        btnProximo.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jPanel6.add(btnProximo);

        btnUltimo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnUltimo.setText(">>");
        btnUltimo.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jPanel6.add(btnUltimo);

        panelTable.add(jPanel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 237, 250, -1));

        tblUnidades.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(tblUnidades);

        panelTable.add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 70, 650, 160));

        lblRowCount.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        lblRowCount.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lblRowCount.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        lblRowCount.setPreferredSize(new java.awt.Dimension(10, 10));
        panelTable.add(lblRowCount, new org.netbeans.lib.awtextra.AbsoluteConstraints(590, 240, 80, 30));

        jToolBar1.setRollover(true);

        btnNovo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/add1-24.png"))); // NOI18N
        btnNovo.setMnemonic('x');
        btnNovo.setToolTipText("");
        btnNovo.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jToolBar1.add(btnNovo);

        btnAlterar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/edit24.png"))); // NOI18N
        btnAlterar.setMnemonic('I');
        btnAlterar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jToolBar1.add(btnAlterar);

        btnSalvar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/incl.png"))); // NOI18N
        btnSalvar.setMnemonic('t');
        btnSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jToolBar1.add(btnSalvar);

        btnCancelar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/can.png"))); // NOI18N
        btnCancelar.setMnemonic('L');
        btnCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jToolBar1.add(btnCancelar);

        btnExcluir.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/icones/delete24.png"))); // NOI18N
        btnExcluir.setMnemonic('I');
        btnExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jToolBar1.add(btnExcluir);

        btnPesquisar1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnPesquisar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/icones/search24.png"))); // NOI18N
        btnPesquisar1.setMnemonic('I');
        btnPesquisar1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jToolBar1.add(btnPesquisar1);

        panelStatusBar.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        panelStatusBar.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        panelStatusBar.setLayout(new org.jdesktop.swingx.HorizontalLayout());

        lblStatusBar.setFont(new java.awt.Font("Calibri", 1, 13)); // NOI18N
        lblStatusBar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        panelStatusBar.add(lblStatusBar);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(panelStatusBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 691, Short.MAX_VALUE)
                    .addComponent(panelTable, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 691, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelTable, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelStatusBar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(49, 49, 49))
        );

        getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));
        jPanel5.setBorder(new org.jdesktop.swingx.border.DropShadowBorder());

        jLabel7.setBackground(new java.awt.Color(0, 0, 0));
        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(0, 0, 255));
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/icones/report32.png"))); // NOI18N
        jLabel7.setText("Controle de Unidades");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 381, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
        );

        getContentPane().add(jPanel5, java.awt.BorderLayout.PAGE_START);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-728)/2, (screenSize.height-569)/2, 728, 569);
    }// </editor-fold>//GEN-END:initComponents
  
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAlterar;
    private javax.swing.JButton btnAnterior;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnExcluir;
    private javax.swing.JButton btnNovo;
    private javax.swing.JButton btnPesquisar;
    private javax.swing.JButton btnPesquisar1;
    private javax.swing.JButton btnPrimeiro;
    private javax.swing.JButton btnProximo;
    private javax.swing.JButton btnSalvar;
    private javax.swing.JButton btnUltimo;
    private javax.swing.JComboBox comboPesquisa;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator12;
    private javax.swing.JSeparator jSeparator13;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JLabel lblRowCount;
    private javax.swing.JLabel lblStatusBar;
    private javax.swing.JPanel panelStatusBar;
    private javax.swing.JPanel panelTable;
    private javax.swing.JTable tblUnidades;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtDescricao;
    private javax.swing.JTextField txtPesquisa;
    // End of variables declaration//GEN-END:variables

    public JPanel getPanelTable() {
        return panelTable;
    }

    public void setPanelTable(JPanel panelTable) {
        this.panelTable = panelTable;
    }
    
    public JPanel getPanelStatusBar() {
        return panelStatusBar;
    }

    public void setPanelStatusBar(JPanel panelStatusBar) {
        this.panelStatusBar = panelStatusBar;
    }   
    
    public JLabel getLblStatusBar() {
        return lblStatusBar;
    }

    public void setLblStatusBar(JLabel lblStatusBar) {
        this.lblStatusBar = lblStatusBar;       
    }
    
    
    // <editor-fold defaultstate="collapsed" desc="Getters and Setters">
    public JButton getBtnPesquisar() {
        return btnPesquisar;
    }

    public void setBtnPesquisar(JButton btPesquisar) {
        this.btnPesquisar = btPesquisar;
    }

    public JButton getBtnAnterior() {
        return btnAnterior;
    }

    public void setBtnAnterior(JButton btnAnterior) {
        this.btnAnterior = btnAnterior;
    }

    public JButton getBtnCancelar() {
        return btnCancelar;
    }

    public void setBtnCancelar(JButton btnCancelar) {
        this.btnCancelar = btnCancelar;
    }

    public JButton getBtnExcluir() {
        return btnExcluir;
    }

    public void setBtnExcluir(JButton btnExcluir) {
        this.btnExcluir = btnExcluir;
    }

    public JButton getBtnNovo() {
        return btnNovo;
    }

    public void setBtnNovo(JButton btnNovo) {
        this.btnNovo = btnNovo;
    }

    public JButton getBtnPrimeiro() {
        return btnPrimeiro;
    }

    public void setBtnPrimeiro(JButton btnPrimeiro) {
        this.btnPrimeiro = btnPrimeiro;
    }

    public JButton getBtnProximo() {
        return btnProximo;
    }

    public void setBtnProximo(JButton btnProximo) {
        this.btnProximo = btnProximo;
    }

    public JButton getBtnSalvar() {
        return btnSalvar;
    }

    public void setBtnSalvar(JButton btnSalvar) {
        this.btnSalvar = btnSalvar;
    }

    public JButton getBtnUltimo() {
        return btnUltimo;
    }

    public void setBtnUltimo(JButton btnUltimo) {
        this.btnUltimo = btnUltimo;
    }

    public JComboBox getComboPesquisa() {
        return comboPesquisa;
    }

    public void setComboPesquisa(JComboBox comboPesquisa) {
        this.comboPesquisa = comboPesquisa;
    }

    public JTable getTblUnidades() {
        return tblUnidades;
    }

    public void setTblUnidades(JTable tblUnidades) {
        this.tblUnidades = tblUnidades;
    }

    public JTextField getTxtCodigo() {
        return txtCodigo;
    }

    public void setTxtCodigo(JTextField txtCodigo) {
        this.txtCodigo = txtCodigo;
    }

    public JTextField getTxtDescricao() {
        return txtDescricao;
    }

    public void setTxtDescricao(JTextField txtDescricao) {
        this.txtDescricao = txtDescricao;
    }

    public JTextField getTxtPesquisa() {
        return txtPesquisa;
    }

    public void setTxtPesquisa(JTextField txtPesquisa) {
        this.txtPesquisa = txtPesquisa;
    }
    
     public JButton getBtnAlterar() {
        return btnAlterar;
    }

    public void setBtnAlterar(JButton btnAlterar) {
        this.btnAlterar = btnAlterar;
    }
    
    public JLabel getLblRowCount() {
        return lblRowCount;
    }

    public void setLblRowCount(JLabel lblRowCount) {
        this.lblRowCount = lblRowCount;
    }  
    
        
    // </editor-fold>
          
    public void icoTitle(){
        java.net.URL imgURL = UnidadeUI.class.getResource("/icones/ico_barra.png");
        setIconImage(new ImageIcon(imgURL).getImage());
    }    
  
    public void initComponentes(){
        initComponents();
    }

    @Override
    public void update() {
        unidadeCtrl.atualizarDadosTable();
    }   
    
    
    
}
